﻿using NoDriverPrintHelperV1d0.ControlUi;
using NoDriverPrintHelperV1d0.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PrintManagement
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
            InitData();
            InitTabControl();
        }
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void InitData()
        {
            PrinterInfoList = GetPrinterInfoByHttp();
            PrinterManageList = new List<ControlPrinterManageV1d0>();
        }
        /// <summary>
        /// 初始化tab页
        /// </summary>
        public void InitTabControl()
        {
            //for (int i = 0; i < PrinterInfoList.Count; i++)
            //{
            //    //原本就有一个tab页
            //    if (i>0) tabControlMain.TabPages.Add(new TabPage("测试"));
            //    //每一个打印机对应一个打印管理页面
            //    ControlPrinterManageV1d0 printerManage = new ControlPrinterManageV1d0();
            //    printerManage.PrinterIp = PrinterInfoList[i].printer_ip;
            //    printerManage.PrinterPort = PrinterInfoList[i].printer_port;
            //    printerManage.PrinterStatus = PrinterInfoList[i].printer_status;
            //    PrinterManageList.Add(printerManage);
            //}
            ////将打印管理页面与tab页关联
            //for (int i = 0; i < tabControlMain.TabCount; i++)
            //{
            //    PrinterManageList[i].Parent = tabControlMain.TabPages[i];
            //    PrinterManageList[i].Location = new Point(2, 2);
            //    PrinterManageList[i].StartRunning();
            //}
        }
        List<PrinterInfoV1d0> PrinterInfoList { get; set; }
        List<ControlPrinterManageV1d0> PrinterManageList { get; set; }
        public List<PrinterInfoV1d0> GetPrinterInfoByHttp()
        {
            List<PrinterInfoV1d0> printerList = new List<PrinterInfoV1d0>();
            PrinterInfoV1d0 printerInfo = new PrinterInfoV1d0();
            printerList.Add(printerInfo);
            return printerList;
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            
        }

        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            foreach(var printerManage in PrinterManageList)
            {
                //关闭连接，及相关线程
                printerManage.DisconnectToPrinter();
                printerManage.StopRunning();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            byte a = 0x01;
            byte b = 0x01;
            byte c = (byte)(a & b);
            string guidString = Guid.NewGuid().ToString();
        }
    }

}
